// Implementation of A* Node
// Nick Kitten

#include "Node.h"
#include <limits>
using namespace std;

Node::Node()
{
	g = INFINITY;
	h = INFINITY;
	f = INFINITY;
	position.x = 0;
	position.y = 0;
	parent = NULL;
}

Node::Node( Position pos, int _g, int _h, Node * par ) 
: position(pos), g(_g),h(_h),parent(par),f(_g+_h), next(NULL), prev(NULL)
{
}

Node::Node( const Node & n )
{
	*this = Node( n.position, n.g, n.h, n.parent );
}

Node::~Node()
{
}

// removes node from the open list
Node * Node::close()
{
	prev->next = next;
	next->prev = prev;
	open = false;
	return this;
}

// pushes node onto the open list
void Node::push( Node * _next )
{
	_next->next = next;
	_next->prev = this;
	next->prev = _next;
	next = _next;
	
	_next->open = true;
}

bool Node::operator>( const Node & rh ) const
{
	return f > rh.f;
}

bool Node::operator<( const Node & rh ) const
{
	return f < rh.f;
}

const int Node::INFINITY = numeric_limits<int>::max();
